package order_pay_type

import (
	"gitee.com/xlizy/common-go/base/enums"
	"strconv"
)

type OrderPayType int

const (
	NotSelected OrderPayType = -1
	Wechat      OrderPayType = iota
	Alipay
)

func (e OrderPayType) Code() int32 {
	return int32(e)
}

func (e OrderPayType) Des() string {
	return enums.BE(e).Des
}

func (e OrderPayType) Enum() string {
	return enums.BE(e).Enum
}

func (e OrderPayType) Val() int {
	return int(e)
}

func (e *OrderPayType) UnmarshalJSON(value []byte) error {
	*e = OrderPayType(enums.UnmarshalEnum(value))
	return nil
}

func (e OrderPayType) MarshalJSON() ([]byte, error) {
	switch e {
	case NotSelected:
		return enums.JsonObj(int(e), "NotSelected", "未选择")
	case Wechat:
		return enums.JsonObj(int(e), "Wechat", "微信支付")
	case Alipay:
		return enums.JsonObj(int(e), "Alipay", "支付宝")
	}
	return []byte(strconv.Itoa(int(e))), nil
}
